package com.qkl.xiatang.app.web.controller;

import com.qkl.xiatang.app.dto.BusinessDTO;
import com.qkl.xiatang.app.service.impl.FeedManagerService;
import com.qkl.xiatang.app.utils.ErrorCodeUtils;
import com.qkl.xiatang.app.utils.Result;
import com.qkl.xiatang.app.utils.appenum.FeedTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("{app.baseURL}")
@Slf4j
public class FeedManagerController {

    @Autowired
    private FeedManagerService feedService;


    /**
     * 查询饲料列表
     * @param params
     * @return
     */
    @GetMapping("/queryFeedList")
    public Result queryFeedList(@RequestParam Map<String,Object> params) {
        String type = StringUtils.trimToEmpty((String) params.get("type"));
        FeedTypeEnum typeEnum = FeedTypeEnum.getTypeEnum(type);
        if(null == typeEnum){
            return Result.error(ErrorCodeUtils.PARAM_ILLEGAL, ErrorCodeUtils.PARAM_ILLEGAL_MSG);
        }
        return ControllerHelper.toQueryResult(feedService.queryFeedList(typeEnum));
    }

    /**
     * 查询库存
     * @return
     */
    @GetMapping("/queryStock")
    public Result queryStock() {
        return ControllerHelper.toQueryResult(feedService.queryStock());
    }


    /**
     * 统计饲料、动保 喂料情况
     * @param params
     * @return
     */
    @GetMapping("/statisticsFeedInfo")
    public Result statisticsFeedInfo(@RequestParam Map<String,Object> params) {
        String pondId = StringUtils.trimToEmpty((String) params.get("pondId"));
        if(StringUtils.isEmpty(pondId)){
            return Result.error(ErrorCodeUtils.PARAM_EMPTY, ErrorCodeUtils.PARAM_EMPTY_MSG);
        }
        return ControllerHelper.toQueryResult(feedService.statisticsFeedInfo(pondId));
    }

}
